package com.sn.author.monitor.handler;

import com.sn.author.common.enums.TaskTypeEnum;

import java.util.HashMap;

/**
 * @Author xiaom
 * @Date 2020/9/22 17:22
 * @Version 1.0.0
 * @Description <>
 **/
public class HandlerFactory {

    private static HashMap<Integer,Class<? extends Handler>> handlerHashMap = new HashMap<>();

    static{
        handlerHashMap.put(TaskTypeEnum.LOGIN.getType(),LoginHandler.class);
        handlerHashMap.put(TaskTypeEnum.ATTENTION.getType(),AttentionHandler.class);
        handlerHashMap.put(TaskTypeEnum.LIKE.getType(),LikeHandler.class);
        handlerHashMap.put(TaskTypeEnum.COMMENT.getType(),CommentHandler.class);
        handlerHashMap.put(TaskTypeEnum.VIDEOINFO.getType(),VideoInfoHandler.class);
        handlerHashMap.put(TaskTypeEnum.IM.getType(),IMHandler.class);
        handlerHashMap.put(TaskTypeEnum.COLLECTION.getType(),CollectionHandler.class);
    }

    /**
     * 处理器工厂
     * @param type 任务类型
     */
    public static Class<? extends Handler> buildHandler(Integer type) throws Exception {
        Class<? extends Handler> cls = handlerHashMap.get(type);
        if(cls == null){
            throw new Exception("未匹配到对应的handler type:" + TaskTypeEnum.match(type).get().getDesc());
        }
        return cls;
    }

}
